package com.zx.sdk.util;

import androidx.annotation.NonNull;

import com.zx.sdk.ZxSDK;
import com.zx.sdk.league.member.BaseLeagueMember;
import com.zx.sdk.model.AdInfo;

public class ZxEventHelper {

    public static final String FETCH = "fetch";
    public static final String LOADED = "loaded";
    public static final String CLICK = "click";
    public static final String EXPOSE = "expose";
    public static final String REWARD = "reward";

    public static ZxEventHandler zxEventHandler;

    public static void setZxEventHandler(ZxEventHandler zxEventHandler) {
        ZxEventHelper.zxEventHandler = zxEventHandler;
    }

    public static void record(String position, String event, AdInfo adInfo, BaseLeagueMember<?, ?, ?, ?,?> member) {
        ZxActionReporter.INSTANCE.record(event, adInfo, getCpm(event, member, adInfo));
        if (zxEventHandler != null) {
            zxEventHandler.onEvent(member.getName(), position, adInfo.getMapAppid(), adInfo.getMapPid(), event);
        }
    }

    @NonNull
    private static String getCpm(String event, BaseLeagueMember<?, ?, ?, ?,?> member, AdInfo adInfo) {
        if (ZxSDK.Bidding.equals(adInfo.getBillType())) {
            if (REWARD.equals(event)) {
                return member.getCachedCpmByPid(adInfo.getDisplay(), adInfo.getMapPid()) + "";
            }
            return "0";
        } else {
            return adInfo.getCpm() * 100 + "";
        }
    }

    public interface ZxEventHandler {
        void onEvent(String leagueName, String position, String mobAppId, String mobPid, String event);
    }
}
